//菜品类型数据存放
import http from '../../../http/http'
import * as url from '../../../api/lypApi'
const state = {
  classifyTableData:[],
};
const actions = {
  getClassifyData({commit}){
    return http({
      url:'/lypApi'+url.GETCLASSIFY,
      method:"post",
    }).then(res=>{
      this.classifyTableData=res.data.list
      commit('addClassifyData',res.data.list)
    })
  },
  deleteClassifyData({commit},obj){
    console.log(obj.name)
    let delData=this.classifyTableData.filter(item=> item.id!=obj.id)
    this.classifyTableData=delData
    http({
      url:`/lypApi${url.DELETECLASSIFY}`,
      method:'post',
      data:{
        // "delFlag": 1,
        "id": obj.id,
        "name": obj.name,
        "num": obj.num
      }
    }).then(res=>{
      console.log(res)
    }).catch(err=>{
      console.log(err)
    })
    commit('addClassifyData',delData)
  },
  selectClassifyData({dispatch,commit},obj){
    console.log(obj)
    // return dispatch('getData').then(() => {
    //   // commit('someOtherMutation')
    // })
    let selectData=[]
    this.classifyTableData.forEach((item)=>{
      if (item[obj[0]]==obj[1]){
        console.log(item)
        selectData.push(item)
      }
    })
    return selectData
  }
};
const mutations = {
  addClassifyData(state,obj){
    state.classifyTableData = obj
  }
}
const  getters= {

};
export default {
  state,
  actions,
  mutations,
  getters
}
